//
//  FWCDiscoverHeaderView.swift
//  微博项目001
//
//  Created by 樊武超 on 16/4/6.
//  Copyright © 2016年 樊武超. All rights reserved.
//

import UIKit

class FWCDiscoverHeaderView: UIView {

    @IBOutlet weak var textField: UITextField!
    @IBOutlet weak var textRight: NSLayoutConstraint!
    @IBOutlet weak var butn: UIButton!
        class func getView() -> FWCDiscoverHeaderView {
            
            return NSBundle.mainBundle().loadNibNamed("FWCDiscoverHeaderView", owner: nil, options: nil).last as! FWCDiscoverHeaderView
        
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        
        let imageView=UIImageView(image: UIImage(named: "searchbar_textfield_search_icon"))
        textField.leftView=imageView
        
        textField.leftView?.frame=CGRectMake(0, 0, self.bounds.height, self.bounds.height)
        
        textField.leftView?.contentMode = .Center
        
        textField.layer.borderWidth=2
        
        textField.layer.borderColor=UIColor.orangeColor().CGColor
        
        textField.leftViewMode = .Always
        
        textField.layer.cornerRadius=17
        
        textField.layer.masksToBounds=true
        
        
        frame=CGRectMake(0, 0, UIScreen.mainScreen().bounds.size.width, self.bounds.height)
    }
    
    @IBAction func textBeginEditing() {
        
        textRight.constant=butn.frame.size.width
        
        UIView.animateWithDuration(0.25) {[weak self] () -> Void in
            
            self!.layoutIfNeeded()
        }
        
    }
    
      @IBAction func butnDidClick() {
        
        endEditing(true)
        textRight.constant=0
        
        UIView.animateWithDuration(0.25) {[weak self] () -> Void in
            
            self!.layoutIfNeeded()
        }

    }
    
}
